APP_PATH = File.expand_path("../../authy-ssh", __FILE__)

desc "Prepare tests"
task :prepare do
  script = File.read(APP_PATH)
  script.gsub!("https://api.authy.com", "http://sandbox-api.authy.com")
  script.gsub!("$APP_ROOT/authy-ssh.conf", "$APP_ROOT/authy-ssh-test.conf")

  File.write("authy-ssh-test", script)

  File.write("authy-ssh-test.conf", %@
banner=Logged in for testing
api_key=0cd08abec2e9b9641e40e9470a7fc336
default_verify_action=disable
user=#{ENV["USER"]}:2
@)
end


desc "Run tests"
task :test => [:prepare] do
  Dir.glob("test_*.rb") do |test_file|
    target = test_file.match("test_(.*)\.rb")[1].to_s.capitalize

    puts "=> Testing #{target} command..."
    system("ruby #{test_file}")
    puts ""
  end
end
